package com.bus.product;

import com.bus.core.PubEndpoint;
import com.bus.core.events.product.ProductRemoteEvent;
import com.bus.product.config.AppConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class ProductApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProductApplication.class, args);
    }

    @Autowired
    private AppConfig appConfig;

    @Autowired
    private PubEndpoint pubEndpoint;

    @RequestMapping(value = "/pub")
    public String publish(String orderNo) {
        ProductRemoteEvent productRemoteEvent = new ProductRemoteEvent(this, appConfig.getAppId(), null, "12313123");
        pubEndpoint.getContext().publishEvent(productRemoteEvent);
        return "ok";
    }
}
